package com.ffcc.fitness.gym.pojo.vo;

import com.ffcc.fitness.gym.pojo.entity.Gym;
import com.ffcc.fitness.user.pojo.vo.UserVO;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
public class GymInfo {
    private Long gymId; // 场馆ID
    private Long userId; // 场馆所有者ID
    private String name; // 场馆名称
    private String description; // 场馆介绍
    private String area; // 所属区域
    private String openingHours; // 营业时间
    private String availableSlots; // 可预约时段
    private String type; // 场馆类型
    private String status; // 场馆状态
    private String images; // 场馆图片（逗号分隔的URL字符串）
    private List<PhotoInfo> photos; // 场馆图片数组（前端使用）
    private String phone; // 电话
    private String address; // 地址
    private String rating; // 评分
    private String tel; // 联系电话(POI字段)
    private String adname; // 区域名称(POI字段)
    private Integer distance; // 距离(POI字段)
    private LocalDateTime createTime; // 创建时间
    private LocalDateTime updateTime; // 更新时间
    private LocalDateTime claimedAt; // 认领时间

    // 认领员工信息
    private UserVO claimedStaff; // 认领该场馆的员工信息
    private Boolean isPoiSource; // 是否来自POI数据源
    private String poiId; // POI数据源ID

    @Data
    public static class PhotoInfo {
        private String title;    // 图片标题
        private String url;      // 图片URL

        public PhotoInfo(String url) {
            this.title = "";
            this.url = url;
        }
    }    public GymInfo(Gym gym) {
        this.gymId = gym.getGymId();
        this.userId = gym.getUserId();
        this.name = gym.getName();
        this.description = gym.getDescription();
        this.area = gym.getArea();
        this.openingHours = gym.getOpeningHours();
        this.availableSlots = gym.getAvailableSlots();
        this.type = gym.getType();
        this.status = gym.getStatus();
        this.images = gym.getImages();
        this.phone = gym.getPhone();
        this.address = gym.getAddress();
        this.createTime = gym.getCreateTime();
        this.updateTime = gym.getUpdateTime();
        this.claimedAt = gym.getClaimedAt();

        // 判断是否来自POI数据源 - 如果有POI ID则表示来自POI数据源
        this.isPoiSource = gym.getPoiId() != null && !gym.getPoiId().isEmpty();
        this.poiId = gym.getPoiId();

        // 转换images字符串为photos数组
        this.photos = new ArrayList<>();
        if (gym.getImages() != null && !gym.getImages().trim().isEmpty()) {
            String[] imageUrls = gym.getImages().split(",");
            for (String url : imageUrls) {
                if (url != null && !url.trim().isEmpty()) {
                    this.photos.add(new PhotoInfo(url.trim()));
                }
            }
        }

        // 设置POI相关字段，使前端兼容
        this.tel = gym.getPhone(); // 将phone映射到tel字段，保持POI字段兼容
        this.adname = gym.getArea(); // 将area映射到adname字段
    }

}
